﻿using System;
using System.Data;
using System.Web.Caching;
using System.Reflection;
using DotNetNuke;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
//using DotNetNuke.Services.Localization;
//using DotNetNuke.Entities.Users;

namespace gdlmo.DNN.Modules.Article.Data
{
	public abstract class DataProvider
	{
		#region Shared/Static Methods
        // singleton reference to the instantiated object 
		private static DataProvider objProvider = null;

		// constructor
		static DataProvider()
		{
			CreateProvider();
		}

		// dynamically create provider
		private static void CreateProvider()
		{
			objProvider = ((DataProvider)DotNetNuke.Framework.Reflection.CreateObject("data", "gdlmo.DNN.Modules.Article.Data", "gdlmo.DNN.Modules.Article"));
		}

		// return the provider
		public static DataProvider Instance()
		{
			return objProvider;
		}

		#endregion

		#region Const Member
		protected const string TABLENAME	= "gdlmo_Article";
		protected const string FIELDLIST	=	"*";		//"articleid";
		protected const string ORDERFIELD	="CreatedDate";
		protected const string KEYFIELD	="articleid";
		protected const string STRWHERE	="articleid>0";
		protected const int	 ORDERTYPE	=1;
		#endregion

		#region "Article Abstract Methods"
		public abstract IDataReader GetArticle(int ArticleID);
		public abstract IDataReader ListArticle();
		public abstract IDataReader GetArticleByCategory(int CategoryId );
//		public abstract int AddArticle(int CategoryId , string Title , DateTime CreatedDate , string CreatedByUser , string CopyFrom , string Author , int Hits , bool IsPassed , string IP , string DeptName , string Summary);
		public abstract int AddArticle(int CategoryId , string Title , DateTime CreatedDate , string CreatedByUser , string CopyFrom , string Author , int Hits , bool IsPassed , string IP , string DeptName , string Summary,string ArticleNames);
		public abstract void UpdateArticle(int ArticleID, int CategoryId , string Title , DateTime CreatedDate , string CreatedByUser , string CopyFrom , string Author , int Hits , bool IsPassed , string IP , string DeptName , string Summary);
		/// <summary>
		/// 更新文章及附件
		/// </summary>
		/// <param name="ArticleID">文章主关键字</param>
		/// <param name="CategoryId">文章所属分类</param>
		/// <param name="Title">文章标题</param>
		/// <param name="CreatedDate">创建日期</param>
		/// <param name="CreatedByUser">创建文章的用户</param>
		/// <param name="CopyFrom">文章来源</param>
		/// <param name="Author">作者</param>
		/// <param name="Hits">点击数</param>
		/// <param name="IsPassed">是否审核通过</param>
		/// <param name="IP">上传者的ip</param>
		/// <param name="DeptName">部门名称</param>
		/// <param name="Summary">摘要</param>
		/// <param name="ArticleNames">附件文件名字符串，用“;”分割</param>
		public abstract void UpdateArticle(int ArticleID, int CategoryId , string Title , DateTime CreatedDate , string CreatedByUser , string CopyFrom , string Author , int Hits , bool IsPassed , string IP , string DeptName , string Summary,string ArticleNames);
		public abstract void DeleteArticle(int ArticleID);
		/// <summary>
		/// 获取文章记录总数
		/// </summary>
		/// <returns></returns>
		public abstract int GetArticleCount();					
		/// <summary>
		/// 根据分类编号获取记录总数
		/// </summary>
		/// <param name="CategoryId">分类编号</param>
		/// <returns>记录总数</returns>
		public abstract int GetArticleCount(int CategoryId);		
		/// <summary>
		/// 根据分类编号获取指定时间范围内的记录总数
		/// </summary>
		/// <param name="CategoryId">分类编号</param>
		/// <param name="StartDate">起始时间</param>
		/// <param name="EndDate">结束时间</param>
		/// <returns>记录总数</returns>
		public abstract int GetArticleCount(int CategoryId,DateTime StartDate,DateTime EndDate);	
		
//		/// <summary>
//		/// 取得指指定页序，分页大小的分页数据
//		/// </summary>
//		/// <param name="PageIndex">页序</param>
//		/// <param name="PageSize">页大小</param>
//		/// <returns>记录集</returns>
//		public abstract IDataReader GetPageData(int PageIndex,int PageSize);
		/// <summary>
		/// 取得指指定页序，分页大小的分页数据
		/// </summary>
		/// <param name="PageIndex">页序</param>
		/// <param name="PageSize">页大小</param>
		/// <param name="PageCount">可返回的页数</param>
		/// <returns>记录集</returns>
		public abstract IDataReader GetPageData(int PageIndex,int PageSize);
//		/// <summary>
//		/// 取得指定分类，指定页序，分页大小的分页数据
//		/// </summary>
//		/// <param name="CategoryId">分类编号</param>
//		/// <param name="PageIndex">页序</param>
//		/// <param name="PageSize">页大小</param>
//		/// <returns>分页记录集</returns>
//		public abstract IDataReader GetPageData(int CategoryId,int PageIndex,int PageSize);
		// <summary>
		/// 取得指定分类，指定页序，分页大小的分页数据
		/// </summary>
		/// <param name="CategoryId">分类编号</param>
		/// <param name="PageIndex">页序</param>
		/// <param name="PageSize">页大小</param>
		/// <param name="PageCount">可返回的页数</param>
		/// <returns>分页记录集</returns>
		public abstract IDataReader GetPageData(int CategoryId,int PageIndex,int PageSize); 
//		/// <summary>
//		/// 取得指定分类，指定页序，分页大小的分页数据,要查询标题的分
//		/// </summary>
//		/// <param name="PageIndex">页序</param>
//		/// <param name="PageSize">页大小</param>
//		/// <param name="keyword">标题</param>
//		/// <returns>分页记录集</returns>
//		public abstract IDataReader GetPageData(int PageIndex,int PageSize,string Title);
//		/// <summary>
//		/// 取得指定分类，指定页序，分页大小的分页数据,要查询标题的分
//		/// </summary>
//		/// <param name="CategoryId">分类编号</param>
//		/// <param name="PageIndex">页序</param>
//		/// <param name="PageSize">页大小</param>
//		/// <param name="keyword">标题</param>
//		/// <returns>分页记录集</returns>
//		public abstract IDataReader GetPageData(int CategoryId,int PageIndex,int PageSize,string Title);
		/// <summary>
		/// 取得分页数据
		/// </summary>
		/// <param name="CategoryId">分类编号</param>
		/// <param name="Title">标题</param>
		/// <param name="StartCreatedDate">开始时间段</param>
		/// <param name="EndCreatedDate">结束时间段</param>
		/// <param name="Author">作者</param>
		/// <param name="DeptName">部门名称</param>
		/// <param name="Summary">摘要</param>
		/// <param name="PageIndex">页序</param>
		/// <param name="PageSize">页大小</param>
		/// <param name="PageCount">返回值参的页总数</param>
		/// <returns>分页记录集</returns>
		public abstract IDataReader GetPageData(int CategoryId,string Title , string StartCreatedDate, string EndCreatedDate , string Author , string DeptName , string Summary,int PageIndex,int PageSize);

		/// <summary>
		/// 增加签收记录
		/// </summary>
		/// <param name="ArticleId">文章编号</param>
		/// <param name="UserId">用户编号</param>
		/// <param name="SignedDate">签收时间</param>
		/// <returns>新增的记录编号</returns>
		public abstract int AddArticleSigned(int ArticleId,int UserId,DateTime SignedDate);
		/// <summary>
		/// 获取指定用户未签收的文件
		/// </summary>
		/// <param name="UserId"></param>
		/// <returns>未签收的文件集</returns>
		public abstract IDataReader GetArticleUnSigned(int UserId);
		/// <summary>
		/// 根据ArticleId取附件列表
		/// </summary>
		/// <param name="ArticleId">文章id</param>
		/// <returns>附件列表</returns>
		public abstract IDataReader ListAccesory(int ArticleId);
		/// <summary>
		/// 取指定Id的附件
		/// </summary>
		/// <param name="AccesoryId">附件Id</param>
		/// <returns>附件</returns>
		public abstract IDataReader GetAccesory(int AccesoryId);
		/// <summary>
		/// 获取未签收用户
		/// </summary>
		/// <param name="PortalId">门户编号</param>
		/// <param name="RoleId">角色编号</param>
		/// <param name="ArticleId">文章编号</param>
		/// <returns>未签收用户</returns>
		public abstract IDataReader GetUnsignedUsers(int PortalId,int RoleId,int ArticleId);

		public abstract IDataReader GetArticleManagerModules(int PortalId);
		#endregion

		#region "Category Abstract Methods"
		public abstract IDataReader GetCategory(int CategoryID,int moduleId);
		public abstract IDataReader ListCategory();
		public abstract IDataReader GetCategoryByModules(int ModuleID );
		public abstract int AddCategory(int ModuleID , string Name , string Description , int ParentID , int Depth , int ViewOrder , string AdminRoles , string EditRoles , string ViewRoles , string CreatedByUser , DateTime CreatedDate , bool IsActive);
		public abstract void UpdateCategory(int CategoryID, int ModuleID , string Name , string Description , int ParentID , int Depth , int ViewOrder , string AdminRoles , string EditRoles , string ViewRoles , string CreatedByUser , DateTime CreatedDate , bool IsActive);
		public abstract void DeleteCategory(int CategoryID);
		 
		#endregion
	}
}

